Skip to main content

ARDK for Android/com.nianticlabs.ardk.wps/WPSSession

WPSSession

class WPSSession : SessionBase<WPSSession>

A session for World Positioning System (WPS) functionality.

WPS provides the 3D position and orientation of the device in geographic coordinates as an alternative to using device GPS and compass heading data. WPS provides greater accuracy and frame-to-frame stability than standard GPS positioning, making it more suitable for AR applications. As the user moves around, WPS maintains the device's position, making it suitable for continuous use over long periods of time and long distances. WPS will work in any location where the phone has a GPS signal, but the accuracy will vary depending on GPS accuracy.

Usage​

1. Acquire the WPS session:

val wpsSession = ardkSession.wps.acquire()

2. Configure the session (optional - defaults are usually sufficient):

val config = WPSConfig(
enableSmoothing = true,
framerate = 120
)
wpsSession.configure(config)

3. Start the session:

wpsSession.start()

4. Poll for location updates regularly:

coroutineScope.launch {
while (trackingStarted) {
delay(1000) // Update every second

// Check feature status
val featureStatus = wpsSession.featureStatus()
if (!featureStatus.isOk()) {
println("WPS has encountered an error")
}

// Get the latest location estimate
when (val result = wpsSession.getLatestLocation()) {
is ARDKResult.Success -> {
val location = result.value
println("GPS: ${location.referenceLatitudeDegrees}, ${location.referenceLongitudeDegrees}")
println("Altitude: ${location.referenceAltitudeMetres} meters")

// Use the transformation matrix for coordinate conversions
val worldPosition = location.trackingToRelativeEdn
// Place AR content using world position
}
is ARDKResult.Error -> {
when (result.code) {
WPSError.NOT_INITIALIZED -> println("WPS still initializing...")
WPSError.NO_GNSS -> println("No GPS signal available")
WPSError.NO_HEADING -> println("No compass data available")
WPSError.TRACKING_FAILED -> println("WPS tracking failed")
else -> println("WPS error: ${result.code}")
}
}
}
}
}

5. Clean up when done:

wpsSession.stop()
wpsSession.close()

Advanced Features​

Converting specific poses to geolocations:

val cameraPose = frame.camera.pose
when (val result = wpsSession.getDevicePoseAsGeolocation(cameraPose)) {
is ARDKResult.Success -> {
val geolocation = result.value
println("Pose location: ${geolocation.latitude}, ${geolocation.longitude}")
}
is ARDKResult.Error -> {
println("Could not get geolocation for pose: ${result.code}")
}
}

See also​

WPSSession.start
WPSSession.stop
WPSSession.configure
WPSSession.getLatestLocation
WPSSession.getDevicePoseAsGeolocation

Functions​

NameSummary
acquire[androidJvm]
@Synchronized
fun acquire(): WPSSession
close[androidJvm]
@Synchronized
open override fun close()
configure[androidJvm]
fun configure(config: WPSConfig)
Configures the session with the specified settings.
featureStatus[androidJvm]
fun featureStatus(): FeatureStatus
Reports errors that have occurred within processes running inside this feature.
getDevicePoseAsGeolocation[androidJvm]
fun getDevicePoseAsGeolocation(pose: Pose): ARDKResult<GeolocationData, WPSError>
Use WPS to get an estimated geolocation for a pose in AR space.
getLatestLocation[androidJvm]
fun getLatestLocation(): ARDKResult<WPSLocation, WPSError>
Gets the transform of the latest geolocation estimate.
start[androidJvm]
fun start()
Starts the WPS system.
stop[androidJvm]
fun stop()
Stops the WPS system.